//
//  QAService.m
//  WisdomStar
//
//  Created by 谭飞 on 2018/11/15.
//  Copyright © 2018年 zhangliwen. All rights reserved.
//

#import "QAService.h"

#import "AskListAPI.h"
#import "AskDetailsAPI.h"
#import "MyQuestionAPI.h"
#import "AddQuestionAPI.h"
#import "AddCommentAPI.h"
#import "AskAcceptAPI.h"
#import "AskLikeAPI.h"

@implementation QAService

+ (void)fetchAskListWithParams:(id)params result:(ReturnBlock)result {
    AskListAPI *api = [[AskListAPI alloc] init];
    api.outerParameters = params;
    [api startWithCompletionBlockWithSuccess:^(__kindof YTKBaseRequest * _Nonnull request) {
        result(request.responseObject);
    } failure:^(__kindof YTKBaseRequest * _Nonnull request) {
        result(request.responseObject);
    }];
}

+ (void)fetchAskDetailsWithParams:(id)params result:(ReturnBlock)result {
    AskDetailsAPI *api = [[AskDetailsAPI alloc] init];
    api.outerParameters = params;
    [api startWithCompletionBlockWithSuccess:^(__kindof YTKBaseRequest * _Nonnull request) {
        result(request.responseObject);
    } failure:^(__kindof YTKBaseRequest * _Nonnull request) {
        result(request.responseObject);
    }];
}

+ (void)fetchMyQuestionWithType:(NSInteger)type result:(ReturnBlock)result {
    MyQuestionAPI *api = [[MyQuestionAPI alloc] init];
    [api startWithCompletionBlockWithSuccess:^(__kindof YTKBaseRequest * _Nonnull request) {
        result(request.responseObject);
    } failure:^(__kindof YTKBaseRequest * _Nonnull request) {
        result(request.responseObject);
    }];
}

+ (void)addQuestionWithParams:(id)params completion:(void (^)(BOOL))complete {
    AddQuestionAPI *api = [[AddQuestionAPI alloc] init];
    api.outerParameters = params;
    [api startWithCompletionBlockWithSuccess:^(__kindof YTKBaseRequest * _Nonnull request) {
        complete(true);
    } failure:^(__kindof YTKBaseRequest * _Nonnull request) {
        complete(false);
    }];
}

+ (void)addCommentWithParams:(id)params completion:(void (^)(BOOL))complete {
    AddCommentAPI *api = [[AddCommentAPI alloc] init];
    api.outerParameters = params;
    [api startWithCompletionBlockWithSuccess:^(__kindof YTKBaseRequest * _Nonnull request) {
        complete(true);
    } failure:^(__kindof YTKBaseRequest * _Nonnull request) {
        complete(false);
    }];
}

+ (void)acceptAskWithParams:(id)params completion:(void (^)(BOOL))complete {
    AskAcceptAPI *api = [[AskAcceptAPI alloc] init];
    api.outerParameters = params;
    [api startWithCompletionBlockWithSuccess:^(__kindof YTKBaseRequest * _Nonnull request) {
        complete(true);
    } failure:^(__kindof YTKBaseRequest * _Nonnull request) {
        IOAResponse *response = [IOAResponse responseWithRequest:request];
        [SVProgressHUD showMessage:response.responseMessage];
        complete(false);
    }];
}

+ (void)askTagsWithParams:(id)params completion:(void (^)(BOOL))complete {
    AskLikeAPI*api = [[AskLikeAPI alloc] init];
    api.outerParameters = params;
    [api startWithCompletionBlockWithSuccess:^(__kindof YTKBaseRequest * _Nonnull request) {
        complete(true);
    } failure:^(__kindof YTKBaseRequest * _Nonnull request) {
        IOAResponse *response = [IOAResponse responseWithRequest:request];
        [SVProgressHUD showMessage:response.responseMessage];
        complete(false);
    }];
}

@end
